package com.hh.hot100;

/**
 * @Author hanghao
 * @Date 2023/6/27 14:35
 * @Version 1.0
 * middle
 * 矩阵置零
 * matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]
 */

public class No73 {
    public void setZeroes(int[][] matrix) {
        int m = matrix.length;       //有几行
        int n = matrix[0].length;    //每一行有几个 就是几列
        boolean[] row = new boolean[m];
        boolean[] col = new boolean[n];
        /**这边写成new Boolean[] 会报出 NullPointerException 空指针异常 因为
         * boolean 是基础数据类型，而 Boolean 是它的封装类(本质上是对象)
         * boolean 创建的对象的值默认是 false，而 Boolean 创建的对象在没有实例化之前是 null
         */
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if(matrix[i][j] == 0) {
                    row[i] = true;
                    col[j] = true;
                }
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if(row[i] || col[j]) {
                    matrix[i][j] = 0;
                }
            }
        }
    }
}
